<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
    <head>
		<%@page import="org.springframework.web.servlet.view.RedirectView"%>
		<%@page import="java.lang.ProcessBuilder.Redirect"%>
		<%@page contentType="text/html" pageEncoding="UTF-8"%>
		<%@page language="java" import="javazoom.upload.*" %>
		<%@page language="java" import="java.util.*" %>
		<%@page errorPage="errorCsv.jsp" %>
		
		<%
		    String direccion = request.getSession().getServletContext().getRealPath("csv/");
		%>
		
		<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
		    <jsp:setProperty name="upBean" property="folderstore" value="<%= direccion%>" />
		    <jsp:setProperty name="upBean" property="whitelist" value="*.csv" />
		    <jsp:setProperty name="upBean" property="overwritepolicy" value="nametimestamp"/>
		</jsp:useBean>
		
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Import CSV</title>
        <meta name="description" content="Metis: Bootstrap Responsive Admin Theme">
        <meta name="viewport" content="width=device-width">
        <link type="text/css" rel="stylesheet" href="assets/css/bootstrap.min.css"/>
        <link type="text/css" rel="stylesheet" href="assets/css/bootstrap-responsive.min.css"/>
        <link type="text/css" rel="stylesheet" href="assets/Font-awesome/css/font-awesome.min.css"/>
        <link type="text/css" rel="stylesheet" href="assets/css/style.css">
        <link type="text/css" rel="stylesheet" href="assets/css/DT_bootstrap.css"/>
        <link rel="stylesheet" href="assets/css/responsive-tables.css">
        
        <link rel="stylesheet" href="assets/css/theme.css">
        
        <script type="text/javascript" src="assets/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
        <!--[if IE 7]>
        <link type="text/css" rel="stylesheet" href="assets/Font-awesome/css/font-awesome-ie7.min.css"/>
        <![endif]-->
        
        <script type="text/javascript">
        	function addData(){
        		var jsonResult = "{array:[";
        		for(var i=0; i<document.getElementById('dataTable').rows.length-1;i++){
        			var newObject = document.createElement();
        			//alert(document.getElementById('dataTable').tBodies[0].rows[i].cells[0].innerHTML);
        			var str = document.getElementById('dataTable').tBodies[0].rows[i].cells[0].innerHTML.substring(46);
        			str = str.substring(0, str.indexOf("\""));
        			if(document.getElementById(str).checked == 1)
        				jsonResult = jsonResult.concat("{'id':"+str+"},");
        		}
        		if(jsonResult=="{array:[")
        			alert("Por favor seleccione un producto");
        		else{
        		jsonResult = jsonResult.substring(0,jsonResult.length-1).concat("]}");
        		window.location.href = "http://localhost:8080/MercadoUtils/addProductData.html?json="+jsonResult;
        		}
        	}
        	
        	function deleteRow(){
        		var jsonResult = "{array:[";
        		for(var i=0; i<document.getElementById('dataTable').rows.length-1;i++){
        			var newObject = document.createElement();
        			//alert(document.getElementById('dataTable').tBodies[0].rows[i].cells[0].innerHTML);
        			var str = document.getElementById('dataTable').tBodies[0].rows[i].cells[0].innerHTML.substring(46);
        			str = str.substring(0, str.indexOf("\""));
        			if(document.getElementById(str).checked == 1)
        				jsonResult = jsonResult.concat("{'id':"+str+"},");
        		}
        		if(jsonResult=="{array:[")
        			alert("Por favor seleccione un producto");
        		else{
        		jsonResult = jsonResult.substring(0,jsonResult.length-1).concat("]}");
        		window.location.href = "http://localhost:8080/MercadoUtils/deleteProductMU.html?json="+jsonResult;
        		}
        	}
        </script>
    </head>
    <body>
        <!-- #wrap -->
        <div id="wrap">
            <!-- #top -->
            <div id="top">
                <!-- .navbar -->
                <div class="navbar navbar-inverse navbar-static-top">
                    <div class="navbar-inner">
                        <div class="container-fluid">
                            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </a>
                            <a class="brand" href="index.html"><img border=0 src="assets/img/logohoriz_Pequeno.png"></a>
                            <!-- .topnav -->
                            <div class="btn-toolbar topnav">
                                <div class="btn-group">
                                    <a class="btn btn-inverse" rel="tooltip" data-original-title="E-mail" data-placement="bottom">
                                        <i class="icon-envelope"></i>
                                        <span class="label label-warning">5</span>
                                    </a>
                                    <a class="btn btn-inverse" rel="tooltip" href="#" data-original-title="Messages"
                                       data-placement="bottom">
                                        <i class="icon-comments"></i>
                                        <span class="label label-important">4</span>
                                    </a>
                                </div>
                                <div class="btn-group">
                                    <a class="btn btn-inverse" data-placement="bottom" data-original-title="Logout" rel="tooltip"
                                       href="login.html"><i class="icon-off"></i></a></div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.navbar -->
            </div>
            <!-- /#top -->

            <!-- BEGIN HEADER.head -->
            <header class="head">
                <div class="search-bar">
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="search-bar-inner">
                                <a id="menu-toggle" href="#menu" data-toggle="collapse"
                                   class="accordion-toggle btn btn-inverse visible-phone"
                                   rel="tooltip" data-placement="bottom" data-original-title="Show/Hide Menu">
                                    <i class="icon-sort"></i>
                                </a>

                                <form class="main-search">
                                    <input class="input-block-level" type="text" placeholder="Live search...">
                                    <button id="searchBtn" type="submit" class="btn btn-inverse"><i class="icon-search"></i>
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>

                </div>
                <!-- ."main-bar -->
                <div class="main-bar">
                    <div class="container-fluid">
                        <div class="row-fluid">
                            <div class="span12">
                                <h3></h3>
                            </div>
                        </div>
                        <!-- /.row-fluid -->
                    </div>
                    <!-- /.container-fluid -->
                </div>
                <!-- /.main-bar -->
            </header>
            <!-- /.head -->

             <!-- #left -->
            <div id="left">
                <!-- .user-media -->
                <div class="media user-media hidden-phone">
                    <a href="" class="user-link">
                        <img src=${requestScope.srcImagen} alt="" class="media-object img-polaroid user-img">
                    </a>

                    <div class="media-body hidden-tablet">
                        <h5 class="media-heading">${requestScope.nombre} <br> ${requestScope.apellido}</h5>
                        <ul class="unstyled user-info">
                            <li><a href="">${requestScope.role}</a></li>
                        </ul>
                    </div>
                </div>
                <!-- /.user-media -->
                <!-- #menu -->
                <ul id="menu" class="unstyled accordion collapse in">
                    <li><a href="home.html"><i class="icon-dashboard icon-large"></i> Dashboard</a></li>
                    <li class="accordion-group ">
                        <a data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav">
                            <i class="icon-tasks icon-large"></i> Productos <span class="label label-inverse pull-right">3</span>
                        </a>
                        <ul class="collapse " id="component-nav">
                            <li><a href="productListPublicados.html"><i class="icon-angle-right"></i>Productos publicados</a></li>
                            <li><a href="productListPendientes.html"><i class="icon-angle-right"></i>Productos pendientes</a></li>
                            <li><a href="listing.html?listing=showForm"><i class="icon-angle-right"></i> Publicar productos</a></li>
                        </ul>
                    </li>
                    <li class="accordion-group ">
                        <a data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav2">
                            <i class="icon-tasks icon-large"></i> Stock <span class="label label-inverse pull-right">1</span>
                        </a>
                        <ul class="collapse " id="component-nav2">
                            <li><a href="StockUpdate.html"><i class="icon-angle-right"></i>Actualizar stock</a></li>
                        </ul>
                    </li>
                    <li class="accordion-group ">
                        <a data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav3">
                            <i class="icon-tasks icon-large"></i> Importar Productos <span class="label label-inverse pull-right">1</span>
                        </a>
                        <ul class="collapse " id="component-nav3">
                            <li><a href="uploadCsv.html"><i class="icon-angle-right"></i>Importar productos desde CSV</a></li>
                        </ul>
                    </li>
                    <li class="accordion-group ">
                        <a data-parent="#menu" data-toggle="collapse" class="accordion-toggle" data-target="#component-nav4">
                            <i class="icon-tasks icon-large"></i>Mensajes<span class="label label-inverse pull-right">1</span>
                        </a>
                        <ul class="collapse " id="component-nav4">
                            <li><a href="AllQuestion.html"><i class="icon-angle-right"></i>Mensajes sin contestar</a></li>
                        </ul>
                    </li>
                </ul>
                <!-- /#menu -->

            </div>
            <!-- /#left -->

            <!-- #content -->
            <div id="content">
                <!-- .outer -->
                <div class="container-fluid outer">
                    <div class="row-fluid">
                        <!-- .inner -->
                        <div class="span12 inner">
                            <!--Begin Datatables-->
                            <div class="row-fluid" id="publicados">
                                <div class="span12">
                                    <div class="box">
                                        <header>
                                            <div class="icons"><i class="icon-cloud-upload"></i></div>
                                            <h5>Importar CSV</h5>
                                        </header>
                                        <div id="collapse4" class="body">
                                            <form method="post" action="uploadCsv.html" name="upform" enctype="multipart/form-data">
<%
if (MultipartFormDataRequest.isMultipartFormData(request)) {
 MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
 String todo = null;
 if (mrequest != null) {
  todo = mrequest.getParameter("todo");
 }
 if ((todo != null) && (todo.equalsIgnoreCase("upload"))) {
  Hashtable files = mrequest.getFiles();
  if ((files != null) && (!files.isEmpty())) {
   java.text.SimpleDateFormat formato = new java.text.SimpleDateFormat("yyMMddHHmmss");
   String archivo = ((UploadFile) mrequest.getFiles().get("uploadfile")).getFileName();
   int posicionPunto = archivo.indexOf(".");
   String nombreImagen = archivo.substring(0, posicionPunto);
   String extension = archivo.substring(posicionPunto);
   nombreImagen = nombreImagen + formato.format(new java.util.Date());
   nombreImagen = nombreImagen + extension;
   ((UploadFile) mrequest.getFiles().get("uploadfile")).setFileName(nombreImagen);
   UploadFile file = (UploadFile) files.get("uploadfile");
   if (file != null) {
    out.println("El archivo: " + file.getFileName() + " se subio correctamente");
    response.sendRedirect("http://localhost:8080/MercadoUtils/uploadCsv.html?upCsv=yes&fileName="+file.getFileName());
   }
   upBean.store(mrequest, "uploadfile");
  } else {
    out.println("Archivos no subidos");
  }
 } else {
   out.println("<BR> todo=" + todo);
 } 
}
%>
	<table>
		<tbody>
			<tr>
				<td><input type="file" name="uploadfile" style="width:400px"/></td>
			</tr>
			<tr>
				<td ><div align="center"><input type="hidden" name="todo" value="upload"/>
					<input align="center" type="submit" value="Importar" /></div>
				</td>
			</tr>
		</tbody>
  </table>
</form>
	                                	</div>
	                            </div>
	                        <!--End Datatables-->
	                    </div>
	                </div>
	              </div>
	           </div>
	        </div>
        </div>
        <!-- /#wrap -->
        <div id="footer">
            <p>2014 © MercadoUtils</p>
        </div>

        <!-- #helpModal -->
        <div id="helpModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel"
             aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="helpModalLabel"><i class="icon-external-link"></i> Help</h3>
            </div>
            <div class="modal-body">
                <p>

                </p>
            </div>
            <div class="modal-footer">

                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            </div>
        </div>
        <!-- /#helpModal -->



        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="assets/js/vendor/jquery-1.10.1.min.js"><\/script>')</script>

        <!--
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
        <script>window.jQuery.ui || document.write('<script src="assets/js/vendor/jquery-ui-1.10.0.custom.min.js"><\/script>')</script>
        -->

        <script src="assets/js/vendor/bootstrap.min.js"></script>

        <script type="text/javascript" src="assets/js/lib/jquery.tablesorter.min.js"></script>
        <script type="text/javascript" src="assets/js/lib/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="assets/js/lib/DT_bootstrap.js"></script>
        <script src="assets/js/lib/responsive-tables.js"></script>
        <script type="text/javascript">
            $(function() {
                metisTable();
            });
        </script>
        <script type="text/javascript" src="assets/js/main.js"></script>
        
        
        
    </body>
</html>